package com.sheng.center.action;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sheng.center.entity.Work;
import com.sheng.center.service.WorkService;

public class WorkAction extends ActionSupport implements ModelDriven<Work>{
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 2994274550234447855L;
	protected String forwardView;
	protected static final String ADD_JSP = "/WEB-INF/page/Work_add.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/Work_edit.jsp";
	protected static final String LIST_JSP = "/WEB-INF/page/Work_list.jsp";
    private Work work = new Work();
    private List<Work> list;
	private WorkService workService;
	@Override
	public Work getModel() {
		return work;
	}
	public String openAdd(){
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	public String openEdit() {
		work = workService.findById(work);
		setForwardView(EDIT_JSP);
		return SUCCESS;
	}
	public String list() {
		list = workService.findAllList(work);
		setForwardView(LIST_JSP);
		return SUCCESS;
	}
	
	public String add() {
		// 获取当前系统时间
		Date date = new Date();
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = format.format(date);
		Timestamp addTime = Timestamp.valueOf(time);// 把String 类型转换成 Timestamp 类型
		work.setCreatedTime(addTime);//写入Timestamp 类型时间
		workService.add(work);
		return list();
	}
	
	public String edit() {
		workService.edit(work);
		return list();
	}
	public String delete() {
		work = workService.findById(work);
		workService.delete(work);
		return list();
	}
	
	
	
	public String getForwardView() {
		return forwardView;
	}
	public void setForwardView(String forwardView) {
		this.forwardView = forwardView;
	}
	public Work getWork() {
		return work;
	}
	public void setWork(Work work) {
		this.work = work;
	}
	public WorkService getWorkService() {
		return workService;
	}
	public void setWorkService(WorkService workService) {
		this.workService = workService;
	}
	public List<Work> getList() {
		return list;
	}
	public void setList(List<Work> list) {
		this.list = list;
	}

}
